<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%String path = request.getContextPath() ;%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %> 
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %>
<%@ taglib uri="/WEB-INF/tld/sys.tld" prefix="sys" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
 <meta name="renderer" content="webkit">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>商家线索列表</title>
<jsp:include page="../../import.jsp" flush="true" />
<!-- 是否显示设置敞口按钮 -->
<sys:funcAuth resCd="LinkCrAmt">
	<span id="isShowLinkCrAmtBtn" />
</sys:funcAuth>
</head>
<body class="iframeBody">
<div class="Wrapper">
<div id="pageInTab" class="pageInTab">
<div tabid="tabA" title="商家线索列表" lselected="true">
<div class="searchArea">
    <form id="searchBar">
        <div class="fieldset1 clearFix">
            <div class="fieldBox" id="searchPrjNmId">
                <div class="label">商家姓名</div>
                <div class="field">
                    <input name="splNm" id="splNm" type="text" class="ui-textbox" value="">
                </div>
            </div>
           <div class="fieldBox" id="searchCstNmId">
                <div class="label">商家手机号</div>
                <div class="field">
                    <input name="contactsMp" id="contactsMp" type="text" class="ui-textbox" value="">
                </div>
            </div>
             <div class="fieldBox" id="searchCstNmId" isyw="0">
                <div class="label">经销商区域</div>
                <div class="field">
                    <!-- <input name="rgnProvCd" id="rgnProvCd" type="text" class="ui-textbox" value=""> -->
                    <jsp:include page="../../system/sysRegion/region.jsp" flush="true" >
						<jsp:param name="regionShowLvl" value="2"/>
					</jsp:include>
                </div>
            </div>
            <div class="fieldBox" id="searchPrjTypCdId">
              <div class="label">跟进状态</div>
                <div class="field">
                	<select name="status"  id="status" >
	                 	<option value=" " selected="selected">--请选择--</option>
	                 	<c:forEach items="${odrShopClueStatusList}" var="kv">
	                  	<option value="${kv.key}">${kv.value}</option>
	                 	</c:forEach>
                	</select>
                </div>
            </div>
            <div class="fieldBox" id="searchCstNmId">
                <div class="label">线索创建时间</div>
                <div class="field">
                    <!-- <input name="beginDt" id="beginDt" type="text" class="ui-datepicker" value="" > -->
                    <input name="startCrtTm" id="startCrtTm" type="text" class="ui-textbox" value="" />
                    <input name="endCrtTm" id="endCrtTm" type="text" class="ui-textbox" value="" />
                </div>
            </div>
            <div class="clearFix"></div>
            <div class="btnsBox">
               <span id="searchBtn"  class="sq-button sq-button-round">查询</span>
               <span id="clearBtn" onclick="clearBtn();" class="sq-button sq-button-round">清空</span>
               <span id="exportDetailBtn" class="sq-button sq-button-round">导出</span>
            </div>
            
        </div>
    </form>
</div>

<div id="ligergrid1" class="sq-grid"></div> 
</div>
</div>
</div>


<div id="chooseFlowDIV" style="display:none">
    <div id="ligergrid_flowStart" class="sq-grid"></div>
</div>
<div id="ywchange_result" style="display:none">
	<form id="ywchange_result_form">
	</form>
</div>

<script src="../js/ligerDateEditor.js" type="text/javascript"></script>
<script type="text/javascript">

$(function () {
    $("#startCrtTm").ligerDateEditor();
    $("#endCrtTm").ligerDateEditor();
})


var isShowLinkCrAmtBtn = $("#isShowLinkCrAmtBtn");
var isLnkCompFlag = '${isLnkCompFlag}';
if(isShowLinkCrAmtBtn.length&&isLnkCompFlag&&isLnkCompFlag==1){
	$("#compCrLim").show();
	$("#compCrLimText").show();
}

	var grid = null;
	var queryFlag = '${queryFlag}'; //只查询列表
	var updateFlag = '${updateFlag}';//业务移交
	var updateSunFlag = '${updateSunFlag}';//供应商及账号修改
	var splPrjViewFlag = '${splPrjViewFlag}';//供应商项目页面
	var mgrPrjViewFlag = '${mgrPrjViewFlag}';//客户经理关联项目页面
	var isLnkPrjViewFlag = '${isLnkPrjViewFlag}';//挂靠公司管理项目页面
	var pageInApp={}; // to 下一级子窗口 接口
    var pageInTab=null;
	$(function () {
		initTab();	
		
	    $("#ligergrid1").ligerGrid({
	    	url: '<%=path%>/carloan/odrshopclueinfo/initList.do',
	    	method : 'get',
	        columns: [
	            { display: '编号', name: 'shopClueNo', align:'center',minWidth: 140 , enabledSort:true},  
	            { display: '经销商名称', name: 'splNm', minWidth: 140,align:'center', enabledSort:true},
	            { display: '联系人姓名', name: 'contactsNm', minWidth: 180,align:'center', enabledSort:true},
	            { display: '联系人手机', name: 'contactsMp', minWidth: 180,align:'center', enabledSort:true},
	            { display: '经销商归属地', name: 'splAddr', width: 100 , enabledSort:true},
	            { display: '跟进状态', name: 'statusNm', minWidth: 140,align:'center', enabledSort:true},
	            { display: '客户经理', name: 'cstMgrNm', width: 100 , enabledSort:true},
	            { display: '省公司', name: 'prOrgCdNm', width: 100 , enabledSort:true},
	            { display: '分公司', name: 'cyOrgCdNm', width: 150, enabledSort:true},
	            { display: '备注', name: 'shopClueRem', minWidth: 140 , enabledSort:true},
	            /* { display: '申请单号', name: 'pNo', minWidth: 140 , 
	              	render: function (rowdata, rowindex, value, column) { 
	            		var h = '';
            			if(value&&value!="null"){				
			            	h+='<a href="javascript:commShowFlow(';
	            		    h+="'"+rowdata.pInstId+"',";
	            		    h+="'"+rowdata.flowAudStsCd+"',";
	            		    h+="'"+rowdata.id+"'";
	            		    h+=')">'+value+'</a>'
            			}
                        return h;
            		},
	            	enabledSort:true}, 
	            { display: '数据来源', name: 'dateResCdNm', minWidth: 100 , enabledSort:true}, */
	            { display: '创建时间', name: 'crtTm', minWidth: 100 , render:renderDate, enabledSort:true}
	        ],
	        pageSize:10,
	        root:'rows',
	        record:'total',
	        hideLoadButton : true,
	        width: '100%',
	        height:'100%',
	        heightDiff:-20,
	        checkbox:true,
	        delayLoad:true,
	        rownumbers:true
	    });
	 //   initOrgTree();
	    grid = liger.get("ligergrid1");
	    grid.setHeight(100);
	    $("#searchBar").ligerForm();
	    $("#searchBtn").click(function(event) {
	         var form = new liger.get("searchBar");
	         var data = form.getData();
	         for (name in data){
	            grid.setParm(name,data[name]);
	         };
	        grid.reload();
	    });
	
	    var form = new liger.get("searchBar");
        var data = form.getData();
        for (name in data){
           grid.setParm(name,data[name]);
        };
        grid.reload();
        
        /* export excel : start */
        //导出详情
        $("#exportDetailBtn").click(function (event) {
            var form = new liger.get("searchBar");
            var data = form.getData();
            $.ajax({
                type: 'get',
                data:data,
                dataType: 'json',
                url: '<%=path%>/carloan/odrshopclueinfo/exportOdrShopClueInfoDetail.do',
                beforeSend: function () {
                    wait_dialog = $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting"});
                },
                success: function (msg) {
                	console.log(JSON.stringify(msg));
                    wait_dialog.close();
                    if (msg.success == 1) {
                        window.open(msg.data);
//                        $.ligerDialog.SQalert({content: msg.info, SQ_type: "success"});
//                        grid.reload($('.pcontrol input', grid.toolbar).val());
                    } else {
                        $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                    }
                }
            });
        });
        /* export excel :end */
	}); 
	    
	var loadedTabs = [];
	//初始化Tab页签
	function initTab(){
		pageInTab = $("#pageInTab").ligerTab({
			height: 'auto',
			contextmenu: false,
			minIframeHeight: GET_minIframeHeight(),
			onAfterSelectTabItem: function(tabid) {
				var selectedRows = grid.getSelectedRows();				
			}
		});
		$.extend(true, pageInApp, {
            pageInTab: pageInTab
        });
	};
	//获取操作列
	function getOptColumn(){		
		var column = {
                display: '查看详情',
                isSort: false,
                width: 150,
                align:'center',
                render: function (rowdata, rowindex, value){
                	 var h="";
                    h+='<a class="sq-button-hasicon" href="javascript:detailBtn(';
                    h+="'"+rowdata.id+"'";
                    h+=')"><i class="sqBtnIco_2"></i>详情</a>';
                    //yaoxr
                    var f = "";
                    if(rowdata.odrStsCd=="4" && StringUtils.isEmpty(rowdata.pNo)
                    		&& StringUtils.isEmpty(rowdata.pInstId)
                    		&& StringUtils.isEmpty(rowdata.flowAudStsCd)){
	                    f+='<a class="sq-button-hasicon" href="javascript:addFlowStart(';
	                    f+="'"+rowdata.id+"'";
	                    f+=')"><i class="sqBtnIco_2"></i>发起流程</a>';
                    }
                    return h+f;
                }
            }
		return column;
	}
	//显示流程
    function commShowFlow(_pInstId, _audStsCd, _businessKey){
    	if(StringUtils.isEmpty(_pInstId)){
    		UIUtils.alertWarning(CommonConstant.C_P_INSTANCEID_NOT_HERE);
    		return;
    	}
    	var _formUrl = "/carloan/odrbscinfo/toAuditOdrInfoPage.do?isDetail=1"+"@@processInstanceId="+_pInstId+"@@odrId=";
    	var params = "?pInsId="+_pInstId+"&status="+_audStsCd+"&businessKey="+_businessKey+"&formUrl="+_formUrl;
    	Add_navTab('tab_cst_invoice_flow_'+_businessKey,'查看流程',"<%=path%>/flow/flow/toFlowShowPageFowBus.do"+params);
    }
	
	//格式化时间
	function renderDate(rowdata, index, value){
		var dateStr = "";
		if(null != value){
			var date = new Date(value);
			dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DDHHMMSS);
		}
		return dateStr;
	}

	function detailBtn(id){
		var fromPrjFlag = true;
		var detailFlag = true;
		
		var _flag = $("#fromPrjFlagId").val();//来自哪里
		if(StringUtils.isNotEmpty(_flag)){
			if(_flag == 'false'){
				fromPrjFlag = false;
			}
		}
		
		Add_navTab('tab_odrbscinfo_detail'+id,'商家线索详情','<%=path%>/carloan/odrbscinfo/toDetailPage.do?fromPrjFlag='+fromPrjFlag+'&&id='+id+'&&detailFlag='+detailFlag);
	}
  
  	function clearBtn(){
    $("#searchBar").ligerForm();
			var form = new liger.get("searchBar");
			form.setData({
				splNm:" ",
				contactsMp:" ",
				rgnProvCd:" ",
				rgnCityCd:" ",
				status:" ",
				startCrtTm:" ",
				endCrtTm:" "
			 });
	}
  	
  	//发起流程 -yaoxr
  	function addFlowStart(odrId){
  		if(!odrId){
  			$.ligerDialog.SQalert({content: "预约ID不能为空.", SQ_type: "warning"});
  			return;
  		}
  		$.ligerDialog.confirm(FlowConstant.FLOW_ADD_START_CONFIRM, function (flag) {
			if(flag == false){
			    return;
            };
	  		var wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting",onClose: function () {}});
            $.ajax({
	    		type: 'post',
	    		dataType:'json',
	    		url: '<%=path%>/carloan/odrbscinfo/addFlowStart.do?odrId='+odrId,
	    		success:function(msg){
	    			 wait_dialog.close();
	    			 if(msg.success == 1){//成功发起流程
	   					 UIUtils.alertSuccessHold1(msg.info);
	    				 //var url = '<%=path%>/flow/flow/getFlowNextAssigne.do?key=' + msg.data;
	    				 //FlowUtils.alertNextFlowAssign(url);
	    				 grid.reload();
	    			 }else if(msg.success == 0){//错误
	   					 UIUtils.alertErrorHold1(msg.info);
	    			 }
	    		}
	    	});
  		});
  	}
</script>

</body>
</html>